/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.android.apps.mytracks.services.sensors.ant;

import com.dsi.ant.exception.AntInterfaceException;

import android.content.Context;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;

/**
 * Tests {@link AbstractAntSensorManager}
 *
 * @author Matthew Simmons
 */
public class AbstractAntSensorManagerTest extends AndroidTestCase {
  private static class WrappedAbstractAntSensorManager extends AbstractAntSensorManager {
    public byte channel;
    public byte messageId;
    public byte[] messageData;

    public WrappedAbstractAntSensorManager(Context context) {
      super(context);
    }

    @Override
    protected void handleOneMessage(byte channel, byte messageId,
        byte[] messageData) throws AntInterfaceException {
      this.channel = channel;
      this.messageId = messageId;
      this.messageData = messageData;
    }

    @Override
    protected void setupAntSensorChannels() {}
  };

  public void testHandleOneMessage() throws Exception {
    WrappedAbstractAntSensorManager manager = new WrappedAbstractAntSensorManager(getContext());

    byte messageId = 15;
    byte[] messageData = { 1, 2, 3 };

    manager.handleMessage(messageId, messageData);

    assertEquals(1, manager.channel);
    assertEquals(messageId, manager.messageId);

    byte[] expectedMessageData = { 2, 3 };
    MoreAsserts.assertEquals(expectedMessageData, manager.messageData);
  }
}

